package com.ftg.learn.chapter07;

/**
 * 二讲for
 * @author XuWy
 * @date 2021/7/12
 *
 * 地球 ： 没有关系
 *          前期绑定 static 类名.方法名（） 类名.属性
 *          ---------初生 new  创建实例
 *          后期绑定
 *          类名  标识符 = new 类名();
 *          标识符.方法名()
 */
public class LearnFor2 {

    /**
     * 这是一个打印星星的方法
     * @param num 个数 形参 -- 实参
     *
     */
    public void printstar(int num){
        for(int i = 0;i < num;i++){
            System.out.print("* ");
        }
    }

    public void printStar2(int row,int col){
        for(int i = 0 ;i < row;i++){
            printstar(col);
            System.out.println();
        }
    }

    public void printStar3(int row,int col){
        for(int i = 0 ;i < row;i++){
            for(int j = 0;j <= i;j++){
                System.out.print("* ");
            }
            System.out.println();
        }
    }

    //两个三角形对角显示
    public void printStar4(int row,int col){
        for(int i = 0 ;i < row*2;i++){
            for(int j = 0;j < col*2;j++){ //1 4 col9
                System.out.print( (i<row && j>=col) ? (j-col<=i ? "* " :"  "): (i>=row && j<col)? (j>=i-row ? "* " : "  ") :"  ");
                //System.out.print("* ");
            }
            System.out.println();
        }
    }

    /**
     * 1.三角形 左下 左上 右上 右下
     * 2.X
     * 3.V
     *
     * */

    //左上
    public void printStar5_2(int row,int col){
        for(int i = 0 ;i < row*2;i++){
            for(int j = 0;j < col*2;j++){
                System.out.print(j<=i ? "* " : "  ");
            }
            System.out.println();
        }
    }

    //左下
    public void printStar5_1(int row,int col){
        for(int i = 0 ;i < row*2;i++){
            for(int j = 0;j < col*2;j++){
                System.out.print( (col*2-j>i)? "* " : "  ");
            }
            System.out.println();
        }
    }

    //右上
    public void printStar5_3(int row,int col){
        for(int i = 0 ;i < row*2;i++){
            for(int j = 0;j < col*2;j++){
                System.out.print( (col*2-j-1<=i) ? "* " : "  ");
            }
            System.out.println();
        }
    }

    //右下
    public void printStar5_4(int row,int col){
        for(int i = 0 ;i < row*2;i++){
            for(int j = 0;j < col*2;j++){
                System.out.print(j>=i ? "* " : "  ");
            }
            System.out.println();
        }
    }
    //X
    public void printStar5_5(int row,int col){
        for(int i = 0 ;i < row;i++){
            for(int j = 0;j < col;j++){
                System.out.print((col-j-1==i || j==i) ? "* " : "  ");
            }
            System.out.println();
        }
    }
    //V
    public void printStar5_6(int row,int col){
        for(int i = 0 ;i < row/2+1;i++){
            for(int j = 0;j < col;j++){
                System.out.print((col-j-1==i || j==i) ? "* " : "  ");
            }
            System.out.println();
        }
    }
    //5
    //    *
    //   ***
    //  *****
    // *******
    //*********
    public void printStar5_7(int row,int col){
        for(int i = 0 ;i < row;i+=2){
            for(int j = 0;j < col;j++){
                System.out.print( col-j-1>i ? " " : "* ");
            }
            System.out.println();
        }
    }

    //6
    public void printStar5_8(int row,int col){
        for(int i = 0 ;i < row;i+=2){
            for(int j = 0;j < col;j++){
                System.out.print(j<i ? " " : "* ");
            }
            System.out.println();
        }
    }

    //7
    /**
     *     *
     *    ***
     *   *****
     *  *******
     * *********
     *  *******
     *   *****
     *    ***
     *     *
     * */
    public void printStar5_9(int row,int col){
        for(int i = 0 ;i < row*2;i+=2) {
            for(int j = 0;j < col;j++) {
                System.out.print( (i<row && j<col)? (col-j-1>i)?" " : "* " : (j<i-row) ? " " : "* ");
            }
            System.out.println();
        }
    }

    //8
    /** *
       ***
      *****
     *******
    *********
    *********
     *******
      *****
       ***
        *
     */
    public void printStar5_10(int row,int col){
        for(int i = 0 ;i < row*2;i+=2){
            for(int j = 0;j < col;j++){
                System.out.print( (i<row && j<col)? (col-j-1>i)?" " : "* " : (j<i-row) ? " " : "* ");
            }
            System.out.println();
        }
    }
    //9
    /**
     *     *
     *    **
     *   ***
     *  ****
     * *****
     *  ****
     *   ***
     *    **
     *     *
     * */
    public void printStar5_11(int row,int col){
        for(int i = 0 ;i < row*2;i++){
            for(int j = 0;j < col;j++){
                System.out.print( (i<row)? (col-j-1>i)?" " : "*" : (j<=i-row) ? " " : "*");
            }
            System.out.println();
        }
    }

    //10
    public void printStar5_12(int row,int col){
        for(int i = 0 ;i < row*2;i++){
            for(int j = 0;j < col;j++){
                System.out.print( ((i<row && j<i)||(i>=row && j<2*row-i)) ? "*":" ");
            }
            System.out.println();
        }
    }
    //11
    public void printStar5_13(int row,int col){
        for(int i = 0 ;i < row;i++){
            for(int j = 0;j < col;j++){
                System.out.print( (j<row-i-1 || j>=row+(row-i-1))? " ":"*");
            }
            System.out.println();
        }
    }
    //12
    /**
     1
     2 3 4
     4 5 6 7 8
     */
    public void printStar5_14(int row){
        for(int i = 1 ;i <= row;i++){
            System.out.print((i%4==0||i==1)?i+"\n":i+" ");
        }
    }
    //13
    /**
     *三角一
     * 1
     * 23
     * 345
     * 4567
     * 56789
     * */
    public void printStar5_15(int row){
        for(int i = 1 ;i <= row;i++){
            for(int j = i;j <i+i;j++){
                System.out.print(j);
            }
            System.out.println();
        }
    }
    //14
    public void printStar5_16(int row){
        int a=0;
        for(int i = 1 ;i < row;i++){
            for(int j = 0;j <i;j++){
                a++;
                System.out.print(a);
            }
            System.out.println();
        }
    }
    //15
    public void printStar5_17(int row,int col){
        int a=0;
        for(int i = 1 ;i <= row;i++){
            for(int j = 1;j <=i;j++){
                for(int s=1;s<=row-i;s++){
                    System.out.print(" ");
                }
                System.out.print(++a);
                if(j==i){
                    for(int x=a-1;x>a-i;x--){
                        System.out.print(x);
                    }
                }
            }
            System.out.println();
        }
    }
    //16
    /**
     * 三角四
     *    1
     *   121
     *  12321
     * 1234321
     * */
    public void printStar5_18(int row,int col){
        for(int i = 1 ;i <= row;i++){
            for(int j=1; j<=row-i;j++){
                System.out.print(" ");
            }
            for(int j = 1;j <=i;j++){
                System.out.print(j);
                if(i==j){
                    for(int k=i-1; k>=1;k--){
                        System.out.print(k);
                    }
                }
            }
            System.out.println();
        }
    }
}
